﻿namespace MLSharp.Evaluation
{
	/// <summary>
	/// Simple binary confusion matrix.
	/// </summary>
	public class ConfusionMatrix
	{
		#region Public Properties 

		/// <summary>
		/// The number of true-positive predictions.
		/// </summary>
		public int TruePositives { get; set; }

		/// <summary>
		/// The number of false-positive predictions.
		/// </summary>
		public int FalsePositives { get; set; }

		/// <summary>
		/// The number of false-negative predictions.
		/// </summary>
		public int FalseNegatives { get; set; }

		/// <summary>
		/// The number of true-negative predictions
		/// </summary>
		public int TrueNegatives { get; set; }

		/// <summary>
		/// The label for the negative row/column in the matrix.
		/// </summary>
		public string NegativeLabel { get; private set; }

		/// <summary>
		/// The label for the positive row/column in the matrix.
		/// </summary>
		public string PositiveLabel { get; private set; }

		#endregion

		#region Public Constructors

		/// <summary>
		/// Creates a binary confusion matrix with the specified labels.
		/// </summary>
		/// <param name="negativeLabel"></param>
		/// <param name="positiveLabel"></param>
		public ConfusionMatrix(string negativeLabel, string positiveLabel)
		{
			NegativeLabel = negativeLabel;
			PositiveLabel = positiveLabel;
		}

		#endregion

		#region Public Methods

		/// <summary>
		/// Gets a string representing the matrix.
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			const string formatString = "\t{0}\t{1}\r\n{0}\t{2}\t{3}\r\n{1}\t{4}\t{5}\r\n";

			return string.Format(formatString, PositiveLabel, NegativeLabel, TruePositives, FalsePositives, FalseNegatives,
			                     TrueNegatives);
		}

		#endregion
	}
}
